package com.block.job.service;

import cn.hutool.core.util.StrUtil;
import com.block.common.service.LogFactory;
import com.block.db.mapper.MerchantDataPushInfoMapper;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;

@Component
public class DeleteMerchantPushDataLessJob {

    private static final Logger log = LogFactory.getJobLog();

    @Resource
    MerchantDataPushInfoMapper merchantDataPushInfoMapper;

    /**
     * 删除当日之前商户初始化数据
     * @throws Exception
     */
    @XxlJob("deleteMerchantPushDataLessJob")
    public void delete() throws Exception {
        XxlJobHelper.log("删除当日之前商户初始化数据---------开始执行--------");

        String dateInfo = LocalDate.now().toString();
        Integer initNumber = merchantDataPushInfoMapper.deleteInitStatusPushDataByDateInfo(dateInfo);

//        Integer matchFailedNumber =merchantDataPushInfoMapper.deleteMatchFailedStatusPushDataByDateInfo(dateInfo);

        // 整理表碎片 OPTIMIZE TABLE
        merchantDataPushInfoMapper.optimizeTable();

        String message = StrUtil.format("删除【INIT】{}", initNumber);
        XxlJobHelper.handleSuccess(message);

        XxlJobHelper.log("删除当日之前商户初始化数据---------结束执行--------"+ message);
    }

}
